/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaboken.tjugoett;

/**
 *
 * @author Mikael K
 */
public abstract class Player {
    // player är en abstrakt klass som visar vad dess subklasser human och computer måste
    // innehålla (play) samt ger dem ett par metoder i arv. Har är-relation till Human och Computer.
    protected Stack deck;
    protected Stack hand = new Stack();
    protected int p; // points
    protected String symbols; // symbols

    public Player(Stack t){
        deck = t;
    }

    public abstract void play();

    public void newGame(){
        hand.throwCards();
        p = 0;
        symbols = "";
    }

    public Card newCard(){
        Card c = deck.removeFromTop();
        hand.putOnTop(c);
        symbols += c.toSymbol() + " ";
        //Calculate points
        int numAces = 0;
        p = 0;
        for(int i = 0; i < hand.numCards(); i++){
            Face f = hand.lookAt(i).getF();
            p += f.value;
            if(f == Face.ACE){
                numAces++;
            }
        }

        for(int j = 1; j <= numAces && p > 21; j++){
            p -= 13; // ace counts as 1
        }

        return c;
    }

    public int points(){
        return p;
    }
}
